package top.fangw.admin.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.nacos.common.utils.CollectionUtils;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.RequiredArgsConstructor;
import top.fangw.admin.mapper.SysRoleJoinApplicationMapper;
import top.fangw.admin.pojo.entity.SysRoleJoinApplication;
import top.fangw.admin.pojo.entity.SysRoleJoinMenu;
import top.fangw.admin.mapper.SysRoleJoinMenuMapper;
import top.fangw.admin.service.ISysRoleJoinMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import top.fangw.common.api.vo.InitRoleJoinMenu;
import top.fangw.common.mybatis.annotation.DyDataSource;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 用途：角色与菜单的关联关系表 服务实现类
 * </p>
 *
 * @author fangw
 * @since 2024-03-02
 */
@Service
@DS("base_info")
public class SysRoleJoinMenuServiceImpl extends ServiceImpl<SysRoleJoinMenuMapper, SysRoleJoinMenu> implements ISysRoleJoinMenuService {

    @Override
    @DyDataSource(tenantId = "#initRoleJoinMenuVo.tenantId", autoTenantId = false)
    public void initUserJoinMenu(InitRoleJoinMenu initRoleJoinMenuVo) {
        if(initRoleJoinMenuVo.getInitRoleJoinMenuList() != null && initRoleJoinMenuVo.getInitRoleJoinMenuList().size() > 0){
            initRoleJoinMenuVo.getInitRoleJoinMenuList().forEach(item ->{
                SysRoleJoinMenu sysRoleJoinMenu = BeanUtil.copyProperties(item, SysRoleJoinMenu.class);
                this.baseMapper.insert(sysRoleJoinMenu);
            });
        }
    }


}
